<?php 
class ManageItem extends Module{
	function ManageItem($row){		
		
		if(User::have_permit(array(ADMIN_ITEM,ADMIN_DEL_ITEM)))
		{
			Module::Module($row);	
			
			$cmd=Url::get('cmd');
			
			switch ($cmd){
				case 'delete':
					
					$id=(int)Url::get('id',0);
					
					if($id)
					{												
						$item = Item::get_item($id);											

						Item::delete_item($id);					
					}	
										
					Url::redirect_url(Url::build_all(array('selected_ids','cmd','id','product_item')));
					break;
				case 'del_cache':
					$id=(int)Url::get('id',0);
					
					if($id)
					{												
						Item::get_item($id,1);											
					}	
										
					Url::redirect_url(Url::build_all(array('selected_ids','cmd','id','product_item')));
					break;
				case 'del_forever':
					if(User::have_permit(ADMIN_DEL_ITEM))
					{
						$id=(int)Url::get('id',0);
						
						if($id)
						{
							Item::delete_item_physical($id);
						}
					}
					
					Url::redirect_url(Url::build_all(array('selected_ids','cmd','id','product_item')));
					break;
				case 'show':					
				case 're_post':					
					$id=(int)Url::get('id',0);
					
					if($id)
					{
						if(MEMCACHE_ON)
						{
							$item_memcache = Item::get_item($id);
							$item_memcache['status'] 			= 1;
							$item_memcache['modify_user_name']  = User::user_name();
							$item_memcache['modify_time'] 		= TIME_NOW;
							
							AZMemcache::do_put("item:$id",$item_memcache);
						}
						
						DB::update('item',array('status'=>1,'modify_user_name'=>User::user_name(),'modify_time'=>TIME_NOW),'id='.$id);
					}
					Url::redirect_url(Url::build_all(array('selected_ids','cmd','id','product_item')));
					break;
				case 'hide':					
					$id=(int)Url::get('id',0);
					
					if($id)
					{
						if(MEMCACHE_ON)
						{
							$item_memcache = Item::get_item($id);
							$item_memcache['status'] 			= 2;
							$item_memcache['modify_user_name']  = User::user_name();
							$item_memcache['modify_time'] 		= TIME_NOW;
							
							AZMemcache::do_put("item:$id",$item_memcache);
						}
						
						DB::update('item',array('status'=>2,'modify_user_name'=>User::user_name(),'modify_time'=>TIME_NOW),'id='.$id);
					}
					Url::redirect_url(Url::build_all(array('selected_ids','cmd','id','product_item')));
					break;
				default:
					require_once 'forms/ManageItem.php';
					$this->add_form(new ManageItemForm());
				break;
			}
		}
		else{
			Url::redirect('sign_in');			
		}
	}
}
?>